#region Copyright
// Copyright (c) 2010, Kazi Manzur Rashid <kazimanzurrashid@gmail.com>.
// This source is subject to the Microsoft Public License. 
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL. 
// All other rights reserved.
#endregion

namespace LiveWriter.Plugins.Snippet
{
    using System;
    using System.Windows.Forms;

    using WindowsLive.Writer.Api;

    internal partial class DefaultSetting : Form
    {
        public DefaultSetting()
        {
            InitializeComponent();
            cboLanguages.Load(SupportedSettings.Languages);
            cboStyles.Load(SupportedSettings.Styles);
        }

        public DefaultSetting(IProperties properties) : this()
        {
            Properties = properties;
            LoadProperties();
        }

        protected IProperties Properties { get; private set; }

        private void LoadProperties()
        {
            cboLanguages.SetSelectedIndex(Properties.Language());
            cboStyles.SetSelectedIndex(Properties.Style());
            chkShowLine.Checked = Properties.ShowLineNumber();
            chkTransparent.Checked = Properties.Transparent();
        }

        private void SaveProperties()
        {
            Properties.Language(((Pair)cboLanguages.SelectedItem).Key);
            Properties.Style(((Pair)cboStyles.SelectedItem).Key);
            Properties.ShowLineNumber(chkShowLine.Checked);
            Properties.Transparent(chkTransparent.Checked);
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            SaveProperties();
            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}